/*
 * @Author: liuqiang
 * @Date: 2021-10-01 17:29:48
 * @LastEditTime: 2021-10-01 21:47:11
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \练习\snake\src\moduls\ScorePanel.ts
 */

// 记分牌类
/**
 * @description: 记分牌
 * @maxLevel {number} 最高等级
 * @upScore {number} 多少分升级
 */
 class ScorePanel {
  private _score = 0;
  private _level = 1;
  private _scoreEle: HTMLElement;
  private _levelEle: HTMLElement;
  // 设置变量 限制最高等级
  private _maxLevel: number
  // 设置变量 表示多少分时升级
  private _upScore: number

  constructor(maxLevel: number = 10, upScore: number = 10) {
    this._scoreEle = document.getElementById('score')!
    this._levelEle = document.getElementById('level')!
    this._maxLevel = maxLevel
    this._upScore = upScore
  }

  // 获取level
  get level() {
    return this._level
  }

  // 设置加分方法
  addScore() {
    this._scoreEle.innerHTML = ++this._score + '';
    // 判断升级条件
    if(this._score % this._upScore === 0) {
      this.levelUp()
    }
  }
  // 升级
  levelUp() {
    if (this._level < this._maxLevel) {
      this._levelEle.innerHTML = ++this._level + '';
    }
  }
}

export default ScorePanel;